﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
using System.Net;


namespace Client
{
    public partial class Client : Form
    {
        TcpClient client = null;
        private const int BUFFER_SIZE = 1024;
        private const int PORT_NUMBER = 2013;
        static ASCIIEncoding encoding = new ASCIIEncoding();
        StreamReader reader;
        StreamWriter writer;
        public Client()
        {
            InitializeComponent();
        
            connect();
        }
        public void connect()
        {
            client = new TcpClient();
           // 1. connect
            client.Connect("127.0.0.1",PORT_NUMBER);
             reader=new StreamReader(client.GetStream());
              writer=new StreamWriter(client.GetStream());
            richTextBox1.Text="Connected to Y2Server.";
            while (true)
            {
                String str;
                // 3. receive
                str = reader.ReadLine();
                Console.WriteLine(str);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                writer.AutoFlush = true;
                // 2. send
                writer.WriteLine(textBox1.Text);
            }
        }
    }
}
